// 当前位置和店铺位置的距离
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { log } from '@/utils'

export const useRemove = (latitude: any, longitude: any) => {
  const distance = ref(0) //

  const getDistance = (la2: any, lo2: any, la6: any, lo6: any) => {
    let La1 = (latitude * Math.PI) / 180.0
    if (la6) {
      La1 = (la6 * Math.PI) / 180.0
    }
    let La2 = (la2 * Math.PI) / 180.0
    let La3 = La1 - La2
    let Lb3 = (longitude * Math.PI) / 180.0 - (lo2 * Math.PI) / 180.0
    if (lo6) {
      Lb3 = (lo6 * Math.PI) / 180.0 - (lo2 * Math.PI) / 180.0
    }
    console.log(La1, La2, La3, Lb3, '参数')

    let distance =
      2 *
      Math.asin(
        Math.sqrt(
          Math.pow(Math.sin(La3 / 2), 2) +
            Math.cos(La1) * Math.cos(La2) * Math.pow(Math.sin(Lb3 / 2), 2),
        ),
      )
    distance = distance * 6378.137
    distance = Math.round(distance * 10000) / 10000
    distance = distance.toFixed(1)
    return distance
  }
  return { getDistance }
}
